package com.lichong.handler;

import com.lichong.common.ResponseVO;
import com.lichong.exception.LimitAccessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lichong
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public ResponseVO handleException(Exception e) {
        log.error("系统内部异常，异常信息", e);
        return new ResponseVO().code(HttpStatus.INTERNAL_SERVER_ERROR).message("系统内部异常");
    }

    @ExceptionHandler(value = LimitAccessException.class)
    public ResponseVO handleLimitAccessException(LimitAccessException e) {
        log.debug("LimitAccessException", e);
        return new ResponseVO().code(HttpStatus.TOO_MANY_REQUESTS).message(e.getMessage());
    }


}
